package com.example.liwushuo.adapter;

import java.util.List;
import com.example.liwushuo.BaseApp;
import com.example.liwushuo.R;
import com.example.liwushuo.bean.Item;
import com.example.liwushuo.bean.ItemBean;
import com.lidroid.xutils.ViewUtils;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

public class GridViewAdapter extends AppAdapter<Item> {

	public GridViewAdapter(Context context, List<Item> list) {
		super(context, list);
	}

	@SuppressWarnings("unchecked")
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		ViewHolder holder;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.one_item, null);
			holder = new ViewHolder(convertView);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		// 为控件赋值
		ItemBean data = list.get(position).getData();
		holder.name.setText(data.getName());
		holder.price.setText(data.getPrice());
		// holder.heart.setText(data.get)
		String url = data.getCover_image_url();
		BaseApp.getBitmapUtils().display(holder.img, data.getCover_image_url());
		return convertView;
	}

	private class ViewHolder {

		ImageView img;
		TextView name;
		TextView price;
		TextView heart;

		public ViewHolder(View convertView) {
			ViewUtils.inject(convertView);
			img = (ImageView) convertView.findViewById(R.id.img_one_id);
			name = (TextView) convertView.findViewById(R.id.one_item_name);
			price = (TextView) convertView.findViewById(R.id.one_item_price);
			heart = (TextView) convertView.findViewById(R.id.one_item_heart);
		}
	}
}
